package com.trade.data;

import java.util.Date;
import java.util.*;
import com.trade.data.type.*;

public class HistoricalDataVO{
	private Long id;
	private String symbol;
	private Date date;
	private Double open;
	private Double high;
	private Double low;
	private Double close;
	private Double volume;
	private Double turnover;

	private SignalType signalType = SignalType.NO_ACTION;

	private IntervalTimeTypes	intervalTimeTypes;

	private ActionType actionType = ActionType.PENDING;

	private StringBuilder signalMessages = new StringBuilder();

	private List<SignalType> buySignalList = new ArrayList<SignalType>();
	private List<SignalType> sellSignalList = new ArrayList<SignalType>();


	//used for calculations like SMA and Average
	private Integer calType;
	private Integer calDays;
	private Double calValue;


	public Long getId(){
		return this.id;
	}

	public String getSymbol(){
		return this.symbol;
	}

	public Date getDate(){
		return this.date;
	}

	public Double getOpen(){
		return this.open;
	}

	public Double getHigh(){
		return this.high;
	}

	public Double getLow(){
		return this.low;
	}

	public Double getClose(){
		return this.close;
	}

	public Double getVolume(){
		return this.volume;
	}

	public Double getTurnover(){
		return this.turnover;
	}

	public SignalType getSignalType(){
		return this.signalType;
	}

	public IntervalTimeTypes getIntervalTimeTypes(){
		return this.intervalTimeTypes;
	}

	public ActionType getActionType(){
		return this.actionType;
	}

	public String getSignalMessages(){
		return this.signalMessages.toString();
	}


	public void setId(Long id){
		this.id =id;
	}

	public void setSymbol(String symbol){
		this.symbol = symbol;
	}

	public void setDate(Date date){
		this.date = date;
	}

	public void setOpen(Double open){
		this.open = open;
	}

	public void setHigh(Double high){
		this.high = high;
	}

	public void setLow(Double low){
		this.low = low;
	}

	public void setClose(Double close){
		this.close = close;
	}

	public void setVolume(Double volume){
		this.volume = volume;
	}

	public void setTurnover(Double turnover){
		this.turnover = turnover;
	}

	public void setSignalType(SignalType signalType){
		this.signalType = signalType;
	}

	public void setActionType(ActionType actionType){
		this.actionType = actionType;
	}


	public void setIntervalTimeTypes(IntervalTimeTypes intervalTimeTypes ){
		this.intervalTimeTypes = intervalTimeTypes;
	}


	public Integer getCalType() {
		return calType;
	}

	public void setCalType(Integer calType) {
		this.calType = calType;
	}

	public Integer getCalDays() {
		return calDays;
	}

	public void setCalDays(Integer calDays) {
		this.calDays = calDays;
	}

	public Double getCalValue() {
		return calValue;
	}

	public void setCalValue(Double calValue) {
		this.calValue = calValue;
	}

	public synchronized void addSignal(SignalType signalType , String message ){
		this.signalMessages.append(message+"\n");

		if( SignalType.BUY == signalType){
			this.buySignalList.add(signalType);
		}else if( SignalType.SELL == signalType){
			this.sellSignalList.add(signalType);
		}

		if( getBuySignalCount() > getSellSignalCount() ){
			setSignalType(SignalType.BUY);
		}else if( getBuySignalCount() < getSellSignalCount() ){
			setSignalType(SignalType.SELL);
		}
		else{
			setSignalType(SignalType.NO_ACTION);
		}
	}

	public Integer getBuySignalCount(){
		return this.buySignalList.size();
	}


	public Integer getSellSignalCount(){
		return this.sellSignalList.size();
	}


	public String toString(){
		StringBuffer sb = new StringBuffer();
		sb.append("symbol="+this.symbol);
		sb.append(",date="+this.date);
		sb.append(",open="+this.open);
		sb.append(",high="+this.high);
		sb.append(",low="+this.low);
		sb.append(",close="+this.close);
		sb.append(",volume="+this.volume);
		if( signalType != null){
			sb.append(",signalType="+this.signalType.getName());
		}
		if( actionType != null){
			sb.append(",actionType="+this.actionType.getName());
		}

		if( intervalTimeTypes != null){
			sb.append(",intervalTimeTypes="+this.intervalTimeTypes);
		}

		sb.append(",calType="+this.calType);
		sb.append(",calDays="+this.calDays);
		sb.append(",calValue="+this.calValue);
		sb.append(",buySignalList="+this.buySignalList);
		sb.append(",sellSignalList="+this.sellSignalList);

		return sb.toString();
	}

}